<?php
class DateTimeFormatter implements Formatter {
    // FIXME: Use UTC time
    const DEFAULT_DATE_FORMAT = 'Y/m/d H:i:s';
    
    /**
     * @var string
     */
    private $format;
    
    public function __construct($format=null) {
        $this->format = $format !== null ? $format : self::DEFAULT_DATE_FORMAT;
    }
    
    /**
     * @param DateTime $value 
     */
    public function format($value) {
        if (!($value instanceof DateTime)) {
            return null;
        }
        else {
            return $value->format($this->format);
        }
    }
    
    /**
     * @param string $value
     * @return DateTime
     */
    public function interpret($value) {
        return DateTime::createFromFormat($this->format, $value);
    }
}
